<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../jquery/jquery-3.6.0.js"></script>
    <script src="../../../wheels/data_utils/math_util.js"></script>
    <script src="../../../wheels/page_utils/anim_util.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .nightsky {
            width: 900px;
            height: 600px;
            background-color: #333;
            border: 10px solid hotpink;
            margin: 30px auto;
            position: relative;
        }

        .fire {
            width: 10px;
            height: 10px;
            border-radius: 50%;
            position: absolute;
            left: 0;
            bottom: 0;
        }
    </style>
</head>

<body>
    <div class="nightsky"></div>

    <script>
        function createFire(left, top) {
            return $("<span></span>")
                .addClass("fire")
                .css({ left, top, backgroundColor: getRandomColor() })
                .appendTo($(".nightsky"))
        }

        $(".nightsky").click(
            function (e) {
                createFire(e.offsetX + "px", $(".nightsky").height() + "px")
                    .animate({
                        top: e.offsetY + "px"
                    }, 200, "linear", function () {
                        $(this).remove()
                        for (let i = 0; i < getRandom(20, 50); i++) {
                            createFire(e.offsetX + "px", e.offsetY + "px")
                                .animate({
                                    left: getRandom(0, $(".nightsky").width()),
                                    top: getRandom(0, $(".nightsky").height())
                                }, 500, "linear", function () {
                                    $(this).remove()
                                })
                        }
                    })
            }
        )
    </script>
</body>

</html>